package com.apes.fn.scm.saleReport.model;

import com.alibaba.fastjson.annotation.JSONField;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.Model;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.jpa.tuple.date.DateTime;
import com.apes.framework.util.ApesConst;
import com.apes.framework.util.DateUtil;
import com.apes.scm.account.tax.model.Tax;
import com.apes.scm.masterdata.car.model.CarLabel;
import com.apes.scm.masterdata.car.model.CarModel;
import com.apes.scm.masterdata.frame.model.Dept;
import com.apes.scm.masterdata.party.model.PartyRole;
import com.apes.scm.masterdata.product.model.*;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.GenerationTime;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.util.Date;

@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = TurnoverDetails.CONST_TABLE_NAME)
public class TurnoverDetails extends Model {
    public static final String CONST_TABLE_NAME = "turnover_details";

    @Id
    @Column(name = "id", length = 32)
    @ApesGenerator(code = CONST_TABLE_NAME, name = "营业额明细", padding = 12)
    @Comment("营业额明细")
    private String id;

    @Column(name = "car_license", length = 16)
    @Comment("车牌")
    private String carLicense;

    @NotNull
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "product_id", referencedColumnName = "id")
    @Comment("商品")
    private Product product;

    @Comment("服务类型")
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "serve_type_id", referencedColumnName = "id", nullable = false)
    private ServeType serveType;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "product_uom_id", referencedColumnName = "id")
    @Comment("计量单位")
    private ProductUom productUom;

    @Column(name = "qty", nullable = false, columnDefinition = ApesConst.FIELD_16_4)
    @Comment("数量")
    private double qty = 0;

    @Column(name = "sales_amount", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("销售金额")
    private double salesAmount = 0;

    @NotNull
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "dept_id", referencedColumnName = "id")
    @Comment("部门")
    private Dept dept;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "company_id", referencedColumnName = "id", nullable = false)
    @Comment("公司")
    private PartyRole company;

    @Column(name = "origin", length = 30)
    @Comment("源单号")
    private String origin;

    @Column(name = "origin_item", length = 500)
    @Comment("源单明细号")
    private String originItem;

    @Column(name = "origin_business_type", length = 32)
    @Comment("源单据类型")
    private String originBusinessType;

    @Comment("源单据创建时间")
    @Column(name = "origin_create_date")
    private Date originCreateDate;

    @Comment("源单据更新时间")
    @Column(name = "origin_update_date")
    private Date originUpdateDate;

    @Column(name = "source", length = 30)
    @Comment("来源单号")
    private String source;

    @Column(name = "source_business_type", length = 64)
    @Comment("来源单据类型")
    private String sourceBusinessType;

    @ManyToOne(fetch = FetchType.LAZY)
    @Comment("商品组")
    @JoinColumn(name = "product_group", referencedColumnName = "id")
    private ProductGroup productGroup;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "classify_id", referencedColumnName = "id")
    @Comment("品类")
    private Classify classify;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "brand_id", referencedColumnName = "id")
    @Comment("品牌")
    private Brand brand;

    @NotNull
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "tax_id", referencedColumnName = "id")
    @Comment("销项税率")
    private Tax tax;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "car_label_id", referencedColumnName = "id")
    @Comment("厂牌")
    private CarLabel carLabel;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "car_model_id",referencedColumnName = "id")
    @Comment("车型")
    private CarModel carModel;

    @Column(name = "suggested_price", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("建议价")
    private double suggestedPrice = 0;

    @Column(name = "price_unit", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("优惠单价")
    private double priceUnit = 0;

    @Column(name = "discount_amount", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("折扣")
    private double discountAmount = 0;

    @Comment("卡券抵扣")
    @Column(name = "coupon_Discount_Amount", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    private double couponDiscountAmount;

    @Column(name = "vip_union_amount", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("会员联盟收入")
    private double vipUnionAmount = 0;

    @Column(name = "vip_union_out_amount", columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("会员联盟支出")
    private double vipUnionOutAmount = 0;

    @Comment("主销售员")
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "main_Salesman", referencedColumnName = "id")
    private PartyRole mainSalesman;

    @Comment("辅销售员")
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "sub_Salesman", referencedColumnName = "id")
    private PartyRole subSalesman;

    @Column(name = "sale_commission", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("销售提成")
    private double saleCommission = 0;

    @Column(name = "worker", length = 500)
    @Comment("施工员")
    private String worker;

    @Column(name = "work_commission",  columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("施工提成")
    private double workCommission = 0;

    @Comment("保呗冲销")
    @Column(name = "baobei_envelope_cash", columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    private double baobeiEnvelopeCash;

    @Comment("红包冲销")
    @Column(name = "red_envelope_cash",columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    private double redEnvelopeCash;

    @Comment("卡券折扣")
    @Column(name = "card_discount", columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    private double cardDiscount;

    @Comment("异业折扣")
    @Column(name = "heterodoxy_discount", columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    private double heterodoxyDiscount;

    @Comment("收银台折扣")
    @Column(name = "cashier_desk_discount_amount", columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    private double cashierDeskDiscountAmount;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "receive_id", referencedColumnName = "id")
    @Comment("领用人员")
    private PartyRole receiver;



}
